#!/bin/bash
if [ $# -ne 3 ]
then
	echo arg length $#
	echo "Requires filtered_associations_file.tsv, phenoProt_transposed.csv, dataset_label as arguments"
	exit
fi
NOW=$(date +"%T")
associations_file=$1
input_transposed_file=$2
dataset_label=$3
features_table=$dataset_label"_features"

# TODO : database connection parameters should be from configuration file...

/tools/bin/python2.5 createSchemaFromTemplate.py $dataset_label ./create_schema_rfex_template.sql
schema_file="./create_schema_rfex_"$dataset_label".sql"

echo begin processing, clean and rebuild schema $(date) for label $dataset_label
mysql -ududley_omics -pdud1ey < $schema_file

echo created schema, begin parsing and loading features $(date) for $associations_file $input_transposed_file
/tools/bin/python2.5 ./parse_features_rfex.py $associations_file $dataset_label
echo parsed and loaded features $(date)

/tools/bin/python2.5 ./parse_associations_rfex.py $associations_file $dataset_label

echo parsed and loaded associations $(date)

/tools/bin/python2.5 ./parse_samples_values.py $input_transposed_file $dataset_label
echo parsed and loaded strains and values $(date)

/tools/bin/python2.5 createSchemaFromTemplate.py $dataset_label ./populate_mv_rf_associations_template.sql
mv_schema_file="./populate_mv_rf_associations_"$dataset_label".sql"
mysql -ududley_omics -pdud1ey < $mv_schema_file
echo populated materialize view, program done $(date)


